{
  "name": "Case 45 - Intelligent Competitor Pricing Threat System",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "value": "1-2tzR_kdHjPAnd2SN469WEc9MevlZV8e",
          "mode": "list",
          "cachedResultName": "Case 45 Competitor Pricing Folder",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1-2tzR_kdHjPAnd2SN469WEc9MevlZV8e"
        },
        "event": "fileCreated",
        "options": {}
      },
      "id": "4a0e707b-87e4-430c-a084-8ea246394496",
      "name": "Watch Competitor Reports Folder",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "typeVersion": 1,
      "position": [
        -2640,
        192
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Cf6MNES8JrQntp3r",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "={{ $json.id }}",
          "mode": "id"
        },
        "options": {}
      },
      "id": "59702a27-33bc-4add-a213-3fb0dbb3f1df",
      "name": "Download Report PDF",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        -2448,
        192
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Cf6MNES8JrQntp3r",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.cloud.llamaindex.ai/api/v1/parsing/upload",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "data"
            }
          ]
        },
        "options": {}
      },
      "id": "ba99670c-7511-40f7-81ab-40715288c0a1",
      "name": "Upload to LlamaIndex Parser",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -2240,
        192
      ]
    },
    {
      "parameters": {
        "amount": 20
      },
      "id": "676a6b1a-f2ca-4919-a6b0-9abc1ea2e979",
      "name": "Wait for PDF Parsing",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        -2048,
        192
      ],
      "webhookId": "ae812b85-700a-4fd1-b29b-47c9f43c22be"
    },
    {
      "parameters": {
        "url": "=https://api.cloud.llamaindex.ai/api/v1/parsing/job/{{ $node[\"Upload to LlamaIndex Parser\"].json[\"id\"] }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "options": {}
      },
      "id": "9e50c50c-2e59-4ee0-ac03-87effd5f24d7",
      "name": "Check Parsing Status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -1840,
        192
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "SUCCESS",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "SUCCESS"
            },
            {
              "conditions": {
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "PENDING",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "PENDING"
            }
          ]
        },
        "options": {}
      },
      "id": "25681214-adbf-410d-a3e7-2f738615608a",
      "name": "Status Router",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.3,
      "position": [
        -1648,
        192
      ]
    },
    {
      "parameters": {
        "url": "=https://api.cloud.llamaindex.ai/api/v1/parsing/job/{{ $node[\"Upload to LlamaIndex Parser\"].json[\"id\"] }}/result/markdown",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "options": {}
      },
      "id": "796dc77a-2416-44d9-be7d-b1c001215b11",
      "name": "Get Parsed Markdown",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -1440,
        96
      ]
    },
    {
      "parameters": {
        "text": "={{ $json.markdown }}",
        "attributes": {
          "attributes": [
            {
              "name": "Report_ID",
              "description": "Unique report identifier from the PDF"
            },
            {
              "name": "Audit_Date",
              "description": "Date when audit was conducted (format: YYYY-MM-DD)"
            },
            {
              "name": "Store_Name",
              "description": "Name of the retail store"
            },
            {
              "name": "Store_Location",
              "description": "City and area of the store"
            },
            {
              "name": "Competitor_Brand",
              "description": "Brand name of the competitor"
            },
            {
              "name": "Product_Name",
              "description": "Full product name of competitor product"
            },
            {
              "name": "Product_Category",
              "description": "Category like Mass Gainers, Protein, etc."
            },
            {
              "name": "Competitor_Pack_Size_Grams",
              "description": "Pack size in grams (numeric value only)"
            },
            {
              "name": "Competitor_Net_Price_INR",
              "description": "Net selling price after discounts (numeric value only)"
            },
            {
              "name": "Competitor_Price_Per_Gram",
              "description": "Price per gram in INR (numeric, 2 decimal places)"
            },
            {
              "name": "Competitor_Stock_Level",
              "description": "Stock level: HIGH or MEDIUM or LOW"
            },
            {
              "name": "Competitor_Shelf_Position",
              "description": "Shelf position description (e.g., Premium Eye-Level, Mid-Level, Bottom)"
            },
            {
              "name": "Our_Product_Name",
              "description": "Our competing product name"
            },
            {
              "name": "Our_Pack_Size_Grams",
              "description": "Our pack size in grams (numeric value only)"
            },
            {
              "name": "Our_Current_Price_INR",
              "description": "Our current selling price (numeric value only)"
            },
            {
              "name": "Our_Price_Per_Gram",
              "description": "Our price per gram in INR (numeric, 2 decimal places)"
            },
            {
              "name": "Our_Stock_Level",
              "description": "Our stock level: HIGH or MEDIUM or LOW"
            },
            {
              "name": "Our_Shelf_Position",
              "description": "Our shelf position description"
            },
            {
              "name": "Active_Promotion",
              "description": "Is competitor running promotion? YES or NO"
            },
            {
              "name": "Field_Agent_Name",
              "description": "Name of the field agent who conducted audit"
            }
          ]
        },
        "options": {
          "systemPromptTemplate": "You are a competitive intelligence data extraction specialist analyzing retail audit reports for HealthBeacon Wellness company.\n\nYour task is to extract structured pricing and competitive intelligence data from field audit reports with absolute precision.\n\nCRITICAL EXTRACTION RULES:\n\n1. NUMERIC VALUES ONLY:\n   - For all price and gram fields, extract ONLY the numeric value\n   - Remove currency symbols (₹, INR), commas, and text\n   - Example: \"₹1,450.00\" → extract as \"1450.00\"\n   - Example: \"3000g (3kg)\" → extract as \"3000\"\n\n2. PRICE PER GRAM CALCULATION:\n   - Always calculate: Net Price ÷ Pack Size in Grams\n   - Round to 2 decimal places\n   - Example: ₹3,360 ÷ 3000g = 1.12\n\n3. STANDARDIZED CATEGORIES:\n   - Stock Level: Must be EXACTLY \"HIGH\" or \"MEDIUM\" or \"LOW\" (uppercase)\n   - Active Promotion: Must be EXACTLY \"YES\" or \"NO\" (uppercase)\n   - If text says \"approximately 40 units\" → extract as \"HIGH\"\n   - If text says \"15-18 units\" → extract as \"MEDIUM\"\n   - If text says \"few units\" or \"5 units\" → extract as \"LOW\"\n\n4. SHELF POSITION:\n   - Extract the complete description as written\n   - Examples: \"Premium Eye-Level, End-Cap Display\", \"Mid-Level Shelf, Standard Placement\"\n   - Preserve the exact wording for accurate threat assessment\n\n5. DATE FORMAT:\n   - Always extract dates in YYYY-MM-DD format\n   - Example: \"December 24, 2025\" → \"2025-12-24\"\n\n6. LOCATION FORMATTING:\n   - Combine Store Name + City/Area\n   - Example: \"Big Bazaar Metro\" + \"Indiranagar, Bangalore\" → \"Big Bazaar Metro, Indiranagar, Bangalore\"\n\n7. HANDLING MISSING DATA:\n   - If a field is not mentioned in the document, return \"NOT_FOUND\"\n   - Never invent or assume data\n   - Never leave fields empty\n\n8. CONSISTENCY:\n   - Extract data exactly as it appears in the source document\n   - Maintain consistency in terminology (don't paraphrase)\n   - Product names should be complete, including brand and variant\n\nQUALITY CHECKS BEFORE RETURNING DATA:\n✓ All numeric fields contain only numbers and decimal points\n✓ Stock levels are HIGH/MEDIUM/LOW only\n✓ Promotion status is YES/NO only\n✓ Dates are in YYYY-MM-DD format\n✓ Price per gram is calculated correctly (2 decimal places)\n\nYour accuracy is critical for automated pricing decisions worth thousands of rupees. Extract with precision."
        }
      },
      "id": "98c81221-695c-4015-852b-89afbb470dac",
      "name": "Extract Intelligence Data",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1.2,
      "position": [
        -1200,
        96
      ]
    },
    {
      "parameters": {
        "jsCode": "const extracted = $node[\"Extract Intelligence Data\"].json.output;\n\nconst ourPrice = parseFloat(extracted.Our_Price_Per_Gram);\nconst compPrice = parseFloat(extracted.Competitor_Price_Per_Gram);\nconst priceGap = ((compPrice - ourPrice) / ourPrice * 100).toFixed(2);\n\nlet threatScore = 0;\n\nconst gapPercent = Math.abs(parseFloat(priceGap));\nif (gapPercent >= 20) {\n  threatScore += 50;\n} else if (gapPercent >= 15) {\n  threatScore += 35;\n} else if (gapPercent >= 10) {\n  threatScore += 25;\n} else if (gapPercent >= 5) {\n  threatScore += 15;\n} else {\n  threatScore += 5;\n}\n\nconst stockLevel = extracted.Competitor_Stock_Level.toUpperCase();\nif (stockLevel.includes('HIGH')) {\n  threatScore += 25;\n} else if (stockLevel.includes('MEDIUM')) {\n  threatScore += 15;\n} else {\n  threatScore += 5;\n}\n\nconst shelfPos = extracted.Competitor_Shelf_Position.toUpperCase();\nif (shelfPos.includes('PREMIUM') || shelfPos.includes('EYE-LEVEL') || shelfPos.includes('END-CAP')) {\n  threatScore += 25;\n} else if (shelfPos.includes('MID') || shelfPos.includes('STANDARD')) {\n  threatScore += 10;\n} else {\n  threatScore += 0;\n}\n\nlet threatLevel = '';\nif (threatScore >= 76) {\n  threatLevel = 'CRITICAL';\n} else if (threatScore >= 51) {\n  threatLevel = 'HIGH';\n} else if (threatScore >= 26) {\n  threatLevel = 'MEDIUM';\n} else {\n  threatLevel = 'LOW';\n}\n\nlet recommendedAction = '';\nif (threatLevel === 'CRITICAL') {\n  recommendedAction = 'URGENT_PRICE_REVIEW';\n} else if (threatLevel === 'HIGH') {\n  recommendedAction = 'PRICE_ADJUSTMENT';\n} else if (threatLevel === 'MEDIUM') {\n  recommendedAction = 'COUNTER_PROMOTION';\n} else {\n  recommendedAction = 'MONITOR_ONLY';\n}\n\nlet suggestedPrice = 0;\nif (threatLevel === 'CRITICAL' || threatLevel === 'HIGH') {\n  suggestedPrice = (compPrice * 1.05).toFixed(2);\n} else if (threatLevel === 'MEDIUM') {\n  suggestedPrice = (compPrice * 1.08).toFixed(2);\n} else {\n  suggestedPrice = ourPrice.toFixed(2);\n}\n\nlet priority = '';\nif (threatScore >= 76) {\n  priority = 'P0';\n} else if (threatScore >= 51) {\n  priority = 'P1';\n} else if (threatScore >= 26) {\n  priority = 'P2';\n} else {\n  priority = 'P3';\n}\n\nreturn {\n  Report_ID: extracted.Report_ID,\n  Audit_Date: extracted.Audit_Date,\n  Store_Location: `${extracted.Store_Name}, ${extracted.Store_Location}`,\n  Competitor_Brand: extracted.Competitor_Brand,\n  Product_Name: extracted.Product_Name,\n  Competitor_Price_Per_Gram: `₹${compPrice}`,\n  Our_Price_Per_Gram: `₹${ourPrice}`,\n  Price_Gap_Percentage: `${priceGap}%`,\n  Comp_Stock_Level: extracted.Competitor_Stock_Level,\n  Comp_Shelf_Position: extracted.Competitor_Shelf_Position,\n  Threat_Score: threatScore,\n  Threat_Level: threatLevel,\n  Recommended_Action: recommendedAction,\n  Suggested_Price_Per_Gram: `₹${suggestedPrice}/g`,\n  Priority: priority,\n  _raw_data: extracted\n};"
      },
      "id": "5ab62040-2d57-4bfd-907e-d2455af8fbab",
      "name": "Intelligence Engine",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -880,
        96
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1gT-BOoj735dEmER9BNTO_IGZ5g_iQFoo78VFqqtstOM",
          "mode": "list",
          "cachedResultName": "Intelligent Competitor Price Log",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gT-BOoj735dEmER9BNTO_IGZ5g_iQFoo78VFqqtstOM/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gT-BOoj735dEmER9BNTO_IGZ5g_iQFoo78VFqqtstOM/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Report_ID": "={{ $json.Report_ID }}",
            "Audit_Date": "={{ $json.Audit_Date }}",
            "Store_Location": "={{ $json.Store_Location }}",
            "Competitor_Brand": "={{ $json.Competitor_Brand }}",
            "Product_Name": "={{ $json.Product_Name }}",
            "Competitor_Price_Per_Gram": "={{ $json.Competitor_Price_Per_Gram }}",
            "Our_Price_Per_Gram": "={{ $json.Our_Price_Per_Gram }}",
            "Price_Gap_Percentage": "={{ $json.Price_Gap_Percentage }}",
            "Comp_Stock_Level": "={{ $json.Comp_Stock_Level }}",
            "Comp_Shelf_Position": "={{ $json.Comp_Shelf_Position }}",
            "Threat_Score": "={{ $json.Threat_Score }}",
            "Threat_Level": "={{ $json.Threat_Level }}",
            "Recommended_Action": "={{ $json.Recommended_Action }}",
            "Suggested_Price_Per_Gram": "={{ $json.Suggested_Price_Per_Gram }}",
            "Priority": "={{ $json.Priority }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Report_ID",
              "displayName": "Report_ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Audit_Date",
              "displayName": "Audit_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Store_Location",
              "displayName": "Store_Location",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Competitor_Brand",
              "displayName": "Competitor_Brand",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Product_Name",
              "displayName": "Product_Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Competitor_Price_Per_Gram",
              "displayName": "Competitor_Price_Per_Gram",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Our_Price_Per_Gram",
              "displayName": "Our_Price_Per_Gram",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Price_Gap_Percentage",
              "displayName": "Price_Gap_Percentage",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Comp_Stock_Level",
              "displayName": "Comp_Stock_Level",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Comp_Shelf_Position",
              "displayName": "Comp_Shelf_Position",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Threat_Score",
              "displayName": "Threat_Score",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Threat_Level",
              "displayName": "Threat_Level",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Recommended_Action",
              "displayName": "Recommended_Action",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Suggested_Price_Per_Gram",
              "displayName": "Suggested_Price_Per_Gram",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Priority",
              "displayName": "Priority",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "dba281eb-1d8f-4c39-948a-e791ad40d9a6",
      "name": "Log to Google Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        -688,
        96
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.Threat_Level }}",
                    "rightValue": "CRITICAL",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "ae77e39f-b98e-4937-b6a5-51be256a0c02"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "SEND_EMAIL"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.Threat_Level }}",
                    "rightValue": "HIGH",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "eff1696f-b00a-4a89-8973-1c93361a9ddc"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "SEND_EMAIL"
            }
          ]
        },
        "options": {
          "fallbackOutput": "none"
        }
      },
      "id": "cdbeb1aa-5399-4c65-9500-1947018c32f3",
      "name": "Should Send Email Alert?",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.3,
      "position": [
        -448,
        96
      ]
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json;\nconst raw = data._raw_data;\n\nconst emailSubject = `🚨 ${data.Priority} - ${data.Threat_Level} Threat: ${data.Competitor_Brand} | ${data.Store_Location}`;\n\nconst emailBody = `\n<!DOCTYPE html>\n<html>\n<head>\n<style>\nbody { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6; color: #333; max-width: 800px; margin: 0 auto; padding: 20px; }\n.header { background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%); color: white; padding: 25px; border-radius: 8px; margin-bottom: 20px; }\n.header h1 { margin: 0; font-size: 24px; }\n.alert-box { background: #fef2f2; border-left: 4px solid #dc2626; padding: 15px; margin: 20px 0; border-radius: 4px; }\n.metrics-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin: 25px 0; }\n.metric-card { background: #f9fafb; padding: 15px; border-radius: 6px; border: 1px solid #e5e7eb; }\n.metric-value { font-size: 24px; font-weight: bold; color: #dc2626; }\n.section { margin: 25px 0; padding: 20px; background: white; border: 1px solid #e5e7eb; border-radius: 8px; }\n.section h2 { margin: 0 0 15px 0; font-size: 18px; border-bottom: 2px solid #e5e7eb; padding-bottom: 10px; }\n.info-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #f3f4f6; }\n.action-box { background: #eff6ff; border: 2px solid #3b82f6; border-radius: 8px; padding: 20px; margin: 25px 0; }\n</style>\n</head>\n<body>\n<div class=\"header\">\n<h1>🚨 ${data.Threat_Level} COMPETITIVE THREAT ALERT</h1>\n<p>Report ID: ${data.Report_ID}</p>\n</div>\n<div class=\"alert-box\">\n<strong>⚠️ IMMEDIATE ACTION REQUIRED</strong><br>\nA ${data.Threat_Level.toLowerCase()} pricing threat detected requiring urgent attention.\n</div>\n<div class=\"metrics-grid\">\n<div class=\"metric-card\">\n<div>Threat Score</div>\n<div class=\"metric-value\">${data.Threat_Score}/100</div>\n</div>\n<div class=\"metric-card\">\n<div>Price Gap</div>\n<div class=\"metric-value\">${data.Price_Gap_Percentage}</div>\n</div>\n<div class=\"metric-card\">\n<div>Priority</div>\n<div class=\"metric-value\">${data.Priority}</div>\n</div>\n</div>\n<div class=\"section\">\n<h2>📊 Intelligence Summary</h2>\n<div class=\"info-row\"><span>Date:</span><span>${data.Audit_Date}</span></div>\n<div class=\"info-row\"><span>Store:</span><span>${data.Store_Location}</span></div>\n<div class=\"info-row\"><span>Competitor:</span><span>${data.Competitor_Brand}</span></div>\n<div class=\"info-row\"><span>Product:</span><span>${data.Product_Name}</span></div>\n<div class=\"info-row\"><span>Their Price:</span><span>${data.Competitor_Price_Per_Gram}</span></div>\n<div class=\"info-row\"><span>Our Price:</span><span>${data.Our_Price_Per_Gram}</span></div>\n<div class=\"info-row\"><span>Stock Level:</span><span>${data.Comp_Stock_Level}</span></div>\n<div class=\"info-row\"><span>Shelf Position:</span><span>${data.Comp_Shelf_Position}</span></div>\n</div>\n<div class=\"action-box\">\n<h3>📋 RECOMMENDED ACTIONS</h3>\n<p><strong>Action:</strong> ${data.Recommended_Action.replace(/_/g, ' ')}</p>\n<p><strong>Suggested Price:</strong> ${data.Suggested_Price_Per_Gram}</p>\n<p><strong>Timeline:</strong> ${data.Priority === 'P0' ? 'Within 24 hours' : 'Within 72 hours'}</p>\n</div>\n</body>\n</html>\n`;\n\nreturn {\n  emailSubject: emailSubject,\n  emailBody: emailBody,\n  recipientEmail: 'commercial.head@healthbeacon.com'\n};"
      },
      "id": "d2b3b6ee-73a9-473e-a13e-3f8608e0de70",
      "name": "Build Email Report",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -192,
        -16
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list"
        },
        "builtInTools": {},
        "options": {}
      },
      "id": "b048a0f2-3786-4fec-8ab8-bf6c2c8a6b1c",
      "name": "GPT-4o Mini",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        -1200,
        288
      ],
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "sendTo": "={{ $json.recipientEmail }}",
        "subject": "={{ $json.emailSubject }}",
        "message": "={{ $json.emailBody }}",
        "options": {}
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        16,
        -16
      ],
      "id": "d8822fc7-6b7e-40f6-9051-33e5c64c7f8b",
      "name": "Send a message",
      "webhookId": "0c3c55ed-e4b0-4b03-b551-5a3afd2328cb",
      "credentials": {
        "gmailOAuth2": {
          "id": "cyqCGWcggZNMcSOv",
          "name": "Gmail account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Watch Competitor Reports Folder": {
      "main": [
        [
          {
            "node": "Download Report PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Report PDF": {
      "main": [
        [
          {
            "node": "Upload to LlamaIndex Parser",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload to LlamaIndex Parser": {
      "main": [
        [
          {
            "node": "Wait for PDF Parsing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for PDF Parsing": {
      "main": [
        [
          {
            "node": "Check Parsing Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Parsing Status": {
      "main": [
        [
          {
            "node": "Status Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Status Router": {
      "main": [
        [
          {
            "node": "Get Parsed Markdown",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait for PDF Parsing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Parsed Markdown": {
      "main": [
        [
          {
            "node": "Extract Intelligence Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Intelligence Data": {
      "main": [
        [
          {
            "node": "Intelligence Engine",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Intelligence Engine": {
      "main": [
        [
          {
            "node": "Log to Google Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to Google Sheet": {
      "main": [
        [
          {
            "node": "Should Send Email Alert?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Should Send Email Alert?": {
      "main": [
        [
          {
            "node": "Build Email Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Email Report": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GPT-4o Mini": {
      "ai_languageModel": [
        [
          {
            "node": "Extract Intelligence Data",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1529443c-a841-4ae5-88c4-d1991d0788b3",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "3a43da28588548e21903e71cf1dc3ddd65c24bf0c62e7e4b77542ffe87ad79c6"
  },
  "id": "JIoidClvWGzBfr0G",
  "tags": []
}